package main

type Node struct {
    Val int
    Left *Node
    Right *Node
    Next *Node
}
func main() {

}

func connect(root *Node) *Node {
	if root != nil {
		left := root.Left
		right := root.Right
		for left != nil {
			left.Next = right  //next赋值
			left = left.Right  //找右节点
			right = right.Left //找左节点
		}
		connect(root.Left)
		connect(root.Right)
	}
	return root
}